package com.alex.seo.domain.campaign;

import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.OneToMany;

import com.alex.seo.contentsource.ContentSource;
import com.alex.seo.domain.site.Site;
import com.alex.seo.service.scheduler.JobScheduler;
import com.alex.seo.usertype.JsonValue;

@Entity
public class PublishingCampaign extends Campaign {

	@OneToMany
	private Collection<Site> sites;

	private JsonValue<JobScheduler> jobScheduler;
	
	private JsonValue<ContentSource> contentSource;

	public PublishingCampaign() {
	}

	public PublishingCampaign(String name, Collection<Site> sites, JobScheduler jobScheduler, ContentSource contentSource) {
		super(name);
		
		this.sites = sites;
		this.jobScheduler = new JsonValue<JobScheduler>(jobScheduler);
		this.contentSource = new JsonValue<ContentSource>(contentSource);
	}

	public Collection<Site> getSites() {
		return sites;
	}

	public void setSites(Collection<Site> sites) {
		this.sites = sites;
	}
	
	public JobScheduler getJobScheduler() {
		return jobScheduler != null ? jobScheduler.get() : null;
	}
	
	public void setJobScheduler(JobScheduler jobScheduler) {
		this.jobScheduler = new JsonValue<JobScheduler>(jobScheduler);
	}
	
	public ContentSource getContentSource() {
		return contentSource != null ? contentSource.get() : null;
	}
	
	public void setContentSource(ContentSource contentSource) {
		this.contentSource = new JsonValue<ContentSource>(contentSource);
	}
	
	@Override
	public String toString() {
		return getClass().getSimpleName() + " {id='" + getId() + "', name='" + getName() + "', sites='" + sites + "'}";
	}
}
